package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.Rest;
import com.qfedu.stussm.service.intf.RestService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/rest/")
public class RestaurantController {
    @Autowired
    private RestService restService;
    //    查询
    @GetMapping("restlist.do")
    @ResponseBody
    public PageBeanVo page(int page, int limit){
        PageBeanVo pageBeanVo = restService.selectAll(page, limit);
        return pageBeanVo;
    }
    //    新增
    @PostMapping("save.do")
    public String save(Rest rest){
        restService.add(rest);
        return "redirect:/restlist.html";
    }
    //    修改
    @PostMapping("update.do")
    @ResponseBody
    public R update(Rest rest){
        System.out.println(rest);
        return restService.update(rest);
    }
    //    s删除
    @PostMapping("del.do")
    @ResponseBody
    public R del(int id){
        return restService.del(id);
    }
}
